package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark45Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark45 extends BaseMark {

    LayoutWatermark45Binding binding;

    public Mark45(@NonNull Context context) {
        super(context);
    }

    public Mark45(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark45(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark45Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark45Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.img);
        }
    }

    @Override
    public void update() {
        setText(binding.binding1, "title45", binding.binding1);

        setText(binding.binding3, "time45", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd"));
        setWeek(binding.binding4);
        setText(binding.binding5, "didian45", binding.binding5);
        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title45", "钢筋数"));
        list.add(new EditItem("time45", "时间", true));
        list.add(new EditItem("didian45", "地点"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd"));
            setWeek(binding.binding4);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public boolean isFullWidth() {
        return true;
    }
}
